<?php
class page extends CI_Controller {
	function index() {
		$this -> pub -> logp('浏览页面设计', '1-2', 'plug_page');
		$da = $this -> pub -> get_setting('页面设计', 'PAGE');
		$this -> load -> view('adminx/page', $da);
	}

	function add() {
		$this -> pub -> logp('创建页面设计', '1-2', 'plug_page');
		$da['name'] = $this -> input -> post('name');
		$da['content'] = $this -> input -> post('content');
		$da['page_del'] = 1;
		$this -> db -> insert('plug_page', $da);
		echo json_encode(array('type' => 1));
	}

	function up() {
		$this -> pub -> logp('页面设计修改 - ' . $this -> input -> post('idx'), '1-2', 'plug_page');
		$da['name'] = $this -> input -> post('name');
		$da['content'] = $this -> input -> post('content');
		$da['page_del'] = 1;
		$this -> db -> update('plug_page', $da, array('id' => $this -> input -> post('idx')));
		echo json_encode(array('type' => 1));
	}

	function get_one() {
		$this -> pub -> logp('获取页面设计信息 - ' . $this -> input -> post('idx'), '1-2');
		$q = $this -> db -> get_where('plug_page', array('id' => $this -> input -> post('idx')));
		if ($q -> num_rows() > 0) {
			$da = $q -> row_array(0);
			$da['typex'] = 1;
			echo json_encode($da);
		} else {
			echo json_encode(array('typex' => 2));
		}
	}

	function del() {
		$this -> pub -> logp('页面设计删除 - ' . $this -> input -> post('idx'), '1-2', 'plug_page');
		$da['type'] = 1;
		$this -> db -> update('plug_page', array('page_del' => 2), array('id' => $this -> input -> post('idx')));
		echo json_encode($da);
	}

	function get() {
		$this -> pub -> logp('获取页面设计信息', '1-2', 'plug_page');
		if ($this -> input -> post('key')) {
			$this -> db -> like('name', $this -> input -> post('key'));
		}
		$this -> db -> where('page_del', 1);
		$q = $this -> db -> get_where('plug_page');
		$da['content'] = '';

		foreach ($q->result_array() as $v) {
			$da['content'] .= '<tr>';
			$da['content'] .= '<td>' . $v['name'] . '</td>';
			$da['content'] .= '<td><a href="/adminx/yl#/plug/page/get/' . $v['id'] . '" class="btn"><i class="fa fa-cloud"></i>  预览</a> <button onclick="alert_ts(\'页面原链接是：' . site_url('plug/page/get/'.$v['id']) . '\')" type="button" class="btn btn-info"><i class="fa fa-link"></i>链接</button> <button onclick="show_up(\'' . $v['id'] . '\')" type="button"  class="btn default"><i class="fa fa-edit"></i>修改</button>  <button onclick="del(\'' . $v['id'] . '\',\'' . $v['name'] . '\')" type="button" class="btn red"><i class="fa fa-trash-o"></i> 删除</button></td>';
			$da['content'] .= '</tr>';
		}
		$da['type'] = 1;
		echo json_encode($da);
	}

}
?>